package com.zhj.psi.web.controller;

import com.zhj.psi.core.mvc.AjaxResult;
import com.zhj.psi.core.mvc.JsonArg;
import com.zhj.psi.web.entity.Customer;
import com.zhj.psi.web.repository.CustomerDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by zhuhuijun on 2017/9/15 16:33
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerDao customerDao;

    @RequestMapping("/findAll")
    public AjaxResult findAll() {
        return new AjaxResult().with(customerDao.findAll());
    }

    @RequestMapping("/findOne")
    public AjaxResult findOne(@JsonArg("id") Long id) {
        return new AjaxResult().with(customerDao.findOne(id));
    }

    @RequestMapping("/save")
    public AjaxResult save(@JsonArg("customer") Customer customer) {
        customerDao.save(customer);
        return new AjaxResult();
    }

    @RequestMapping("/update")
    public AjaxResult update(@JsonArg("customer") Customer customer) {
        customerDao.saveAndFlush(customer);
        return new AjaxResult();
    }

    @RequestMapping("/remove")
    public AjaxResult remove(@JsonArg("id") Long id) {
        customerDao.delete(id);
        return new AjaxResult();
    }


}
